package com.ruoyi.flowable.listener;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.flowable.common.constant.ProcessConstants;
import com.ruoyi.flowable.factory.FlowServiceFactory;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;

import java.util.Map;

@Slf4j
public class MultiInstanceCompletionEndListener implements ExecutionListener {
    FlowServiceFactory flowServiceFactory;


    public MultiInstanceCompletionEndListener() {
        flowServiceFactory = SpringUtils.getBean("flowServiceFactory");
    }


    //主子流程同步及 多实例完成条件
    @Override
    public void notify(DelegateExecution execution) {
        //主流程变量
        Map<String, Object> mainvariables = execution.getVariables();
        //主流程id
        String parentProcessInstanceId = (String) mainvariables.get("parentProcessInstanceId");
        int flag= (int) mainvariables.get("userIdflag");
        mainvariables.replace("userIdflag", flag+1);
        flowServiceFactory.getRuntimeService().setVariables(parentProcessInstanceId, mainvariables);
    }
}
